package cn.bdqn.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;



@Configuration
public class MQConfig {

    /**
     * 创建一个队列
     *
     * @return
     */
    @Bean
    public Queue queue() {
        return new Queue("OPC-Queue");
    }
    @Bean
    public Queue OPCQueue() {
        return new Queue("DOCTOR-Queue");
    }

    /**
     * 订阅模式交换机
     *
     * @return
     */
    @Bean
    public FanoutExchange fanoutExchange() {
        return new FanoutExchange("fanoutExchange");
    }

    /**
     * 绑定交换机(发布订阅)
     * @param queue 队列
     * @param fanoutExchange 订阅模式交换机
     * @return
     */
    @Bean
    public Binding bindingFanoutExchange(Queue queue, FanoutExchange fanoutExchange){
        return BindingBuilder.bind(queue).to(fanoutExchange);
    }
    /**
     * 路由(支持通配符方式)交换机
     *
     * @return
     */
    @Bean
    public TopicExchange topicExchange() {
        return new TopicExchange("topicExchange");
    }

    /**
     * 绑定路由(支持通配符方式)交换机
     * @param queue
     * @param topicExchange
     * @return
     */
    @Bean
    public Binding bindingTopicExchange(Queue queue, TopicExchange  topicExchange){
        return BindingBuilder.bind(queue).to(topicExchange).with("TopicKEY");
    }

    /**
     * 路由模式的交换机
     *
     * @return
     */
    @Bean
    public DirectExchange directExchange() {
        return new DirectExchange("directExchange");
    }
    /**
     * 绑定路由模式的交换机
     * @param queue
     * @param directExchange
     * @return
     */
    @Bean
    public Binding bindingDirectExchange(Queue queue, DirectExchange  directExchange){
        return BindingBuilder.bind(queue).to(directExchange).with("DirectKEY");
    }

}